<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登录</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/login.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.8.3.min.js"></script>
<script>
var index =1;
var un = false;
var up = false;
var cd = false;

	$(function(){
		setInterval('showNext()',30000);
		$('#codeImg').click(function(){
			loadCode();
		});
		$('#code').keyup(function(){
			ckCode();	
		});
		$('#uname').keyup(function(){
			ckName();	
		});
		$('#upass').keyup(function(){
			ckPass();	
		});
		$('#form1').submit(function(){
			ckLogin();
			return false;	
		});
	});
	
	function showNext(){
				$('#bgimg').slideToggle(600);
				setTimeout('show2()',200);
				
			
			$('#bgimg').css('background','url(img/bg/'+index+'.jpg)');
		
			if(index<5){
				index++;
			}else{
				index=1;
			}
			$('#bgimg2').css('background','url(img/bg/'+index+'.jpg)');
			
	}
	
	function show2(){
		$('#bgimg2').slideToggle(600);	
	}
	
	function loadCode(){
		var ttime = new Date();
		$('#codeImg').attr('src','createCodeUtil.action?q='+ttime.getTime());
	}
	
	function ckLogin(){
		if(un && up && cd){
			$('#btn_').html('登录中...');
			var date = new Date();
			$.post('loginUser.action',{'user.usEmpid':$('#uname').val(),'user.usPass':$('#upass').val(),'q':date.getTime()},function(data){
				if(data=='1'){
					$('#btn_').html('登录成功,请稍候...');
					setTimeout(function(){
						location.href='index.jsp';
					},1500);
				}else{
					$('#btn_').html('用户名或密码错误,请重试！');
					setTimeout(function(){
						$('#btn_').html('<input name="btnlogin" type="submit" id="btnlogin" value="登录" />');
						$('#form1')[0].reset();	
					},2500);
				}
			});
		}else{
			$('#btn_').html('<input name="btnlogin" type="submit" id="btnlogin" value="登录" />');
			$('#form1')[0].reset();	
		}
	}
	
	function ckName(){
		if($('#uname').val().length>=3){
			un=true;
			$('#uname').css('backgroundColor','#FFFFFF');
		}else{
			un=false;	
			$('#uname').css('backgroundColor','#930');
		}
		return un;
	}
	
	function ckPass(){
		if($('#upass').val().length>=6){
			up=true;
			$('#upass').css('backgroundColor','#FFFFFF');
		}else{
			up=false;	
			$('#upass').css('backgroundColor','#930');
		}
		return up;
	}
	
	function  ckCode(){
		if($('#code').val().length>=4){
			var date = new Date();
			$.post('eqCodeUtil.action',{'code':$('#code').val(),'q':date.getTime()},function(data){
					if(data=='1'){
						cd=true;
						$('#code').css('backgroundColor','#FFFFFF');
					}else{
						cd=false;
						$('#code').css('backgroundColor','#930');
					}
					return cd;
			});
		}else{
			cd = false;
		}
	}
	
</script>
</head>

<body>

<div id="bgimg" class="bgimg">  </div>
<div id="bgimg2" class="bgimg" style="display:none;">  </div>

<div id="login">
  <div id="left"><img src="img/Users.png" width="128" height="128" alt="头像" /></div>
  <div id="right">
 	 <form id="form1" name="form1" method="post">
        <div class="r_sline">
          <label for="uname">用户名：</label>
          <input name="uname" type="text" id="uname" maxlength="30" />
        </div>
       <div class="r_sline">
         <label for="upass">密码：</label>
         <input name="upass" type="password" id="upass" maxlength="30" />
       </div>
        <div class="r_sline">
          <label for="code">验证码：</label>
           <input name="code" type="text" id="code" maxlength="8" />
        <img src="createCodeUtil.action" alt="看不清？" name="codeImg" height="24" id="codeImg" />
         </div>
        
        <div class="r_sline" id="btn_">
        	<input name="btnlogin" type="submit" id="btnlogin" value="登录" />
        </div>
        
    </form>
  </div>
  <div id="msg"></div>
</div>

    <div id="context">
    crm version:1.0.0<br />
    	vi1 &copy; 版权所有
    </div>
</body>
</html>
